<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>示例3</title>
</head>
<body>
    <script>
        //工厂函数
        function createStudent(name,age){
            const p = new Object()
            p.name = name
            p.age = age
            p.show = function (){
                alert(`姓名:${this.name} 年龄:${this.age}`)
            }
            return p
        }

        const stu1 = createStudent('jack',19)
        const stu2 = createStudent('tom',22)
        stu1.show()
        stu2.show()
    </script>
</body>
</html>